#include "spotify.h"

#ifdef ENABLE_SPOTIFY

#define MPD

#include <stdio.h>
#include <stdlib.h>

#include "song_print.h"
#include "song.h"
#include "client.h"
#include "playlist.h"
#include "queue.h"
#include "tag.h"

#include "despotify.h"
#include "conf.h"

void print_tracks(struct client * client, struct track* head)
{
    if (!head) {
        g_warning(L" <empty playlist>\n");
        return;
    }

    int count = 1;
    int b=0;
    char uri[200];
    struct playlist playlist;
    playlist_init(&playlist);
    for (struct track* t = head; t; t = t->next) 
    {
      if (t->has_meta_data)
      {
					playlist.queue.items[b].song = spotify_to_mpd_song(t);
					song_print_info(client, playlist.queue.items[b].song);
      }
    }
    playlist_finish(&playlist);
}

int spotify_search(struct locate_item_list * to_search, struct search_data *data)
{
	struct search_result * search;
	struct ds_playlist * searchlist;
	struct song song;
  search = despotify_search(despotify_session, to_search->items->needle, MAX_SEARCH_RESULTS);
  if (!search) {
      g_warning("Search failed: %s\n", despotify_get_error(despotify_session));
      return -1;
  }
  searchlist = search->playlist;
  
	if (searchlist) {
	  if (search->total_tracks > 0) {
      print_tracks(data->client, search->tracks);
   }
	}
  
  despotify_free_search(search);
  
  return 0;
}
#endif
